#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
long long n,que[10005],fr=-1,la,ans,tong[1005];
int wd[10005];
void read(int &x){ 
	int f=1;x=0;char s=getchar();
	while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
	while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}
	x*=f;
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		read(wd[i]);
		tong[wd[i]]++;
	}
	int cnt=0;
	for(int i=1;i<=1000;i++)
	{
		for(int j=1;j<=tong[i];j++)
		wd[++cnt]=i;
	}
	int i=0;
	for(int j=1;j<n;j++)
	{
		if(la==0)
		que[la++]=wd[++i]+wd[++i];
		else{
			i++;fr++;
			if(wd[i]<que[fr]&&i<=n||fr==la)
			{
				que[la]+=wd[i];
				if(i==n) i=n+1;
				fr--;
			}
			else{
				que[la]+=que[fr];
				i--;				
			}
			i++;fr++;
			if(wd[i]<que[fr]&&i<=n||fr==la)
			{
				que[la]+=wd[i];
				if(i==n) i=n+1;
				fr--;
			}
			else{
				que[la]+=que[fr];
				i--;				
			}			
			la++;	//cout<<j<<' '<<que[la-1]<<endl;	
		}
		ans+=que[la-1];
		
	}
	cout<<ans;
	return 0;
}
